//
//  alertview.m
//  PaiQuan
//
//  Created by Mac on 16/7/12.
//  Copyright © 2016年 huigu. All rights reserved.
//


#import "alertview.h"

@implementation alertview
{
    
}
-(instancetype)init{
    if (self = [super init]) {
        self.layer.cornerRadius == 8;
        self.layer.masksToBounds = YES;
    }
    
    return self;
}
-(void)altTitle:(NSString *)Title ximg:(UIImage *)imgage NameTitle:(NSString*)nameTitle addressTitle:(NSString*)addressTitle
{
    
    
    UILabel *alttitle=[[UILabel alloc] init];
    alttitle.text=Title;
//    [alttitle setTextAlignment:NSTextAlignmentCenter];
   
    [alttitle setFont:[UIFont systemFontOfSize:16]];
    [alttitle setTextColor:[UIColor  blackColor]];
    [alttitle setFrame:CGRectMake(RATIO(44), RATIO(38), RATIO(540), RATIO(40))];
    [self addSubview:alttitle];
    
    UIImageView *Ximg=[[UIImageView alloc] initWithFrame:CGRectMake(RATIO(44), RATIO(126), RATIO(96), RATIO(96))];
    
    Ximg.image = imgage;
   
//    [Ximg setUserInteractionEnabled:YES];
//    UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTap:)];
//    [Ximg addGestureRecognizer:singleTap];
    [self addSubview:Ximg];
    
    
    UILabel *altcontent=[[UILabel alloc] init];
    [altcontent setText:addressTitle];
    [altcontent setFont:FONT(16)];
    [altcontent setTextAlignment:NSTextAlignmentLeft];
    [altcontent setTextColor:PQ_COLOR_SimpleGary];
 
    [altcontent setFrame:CGRectMake(RATIO(178), RATIO(176),ScreenW-RATIO(178), RATIO(40))];
   
  
    [self addSubview:altcontent];
    
    UILabel *addressLab=[[UILabel alloc] init];
    [addressLab setText:nameTitle];
    [addressLab setFont:FONT(16)];
    [addressLab setTextAlignment:NSTextAlignmentLeft];
    [addressLab setTextColor:PQ_COLOR_SimpleGary];
    
    [addressLab setFrame:CGRectMake(RATIO(178), RATIO(126),ScreenW-RATIO(178), RATIO(40))];
    
    
    [self addSubview:addressLab];
    

        
        UIButton *altbut=[UIButton buttonWithType:UIButtonTypeCustom];
        [altbut setTitle:@"取消" forState:UIControlStateNormal];
        [altbut setTitle:@"取消" forState:UIControlStateHighlighted];
        [altbut setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [altbut setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [altbut setBackgroundColor:[UIColor whiteColor]];
        [altbut setTag:0];
        altbut.frame = CGRectMake(0, RATIO(244), RATIO(270), RATIO(100));
        [altbut addTarget:self action:@selector(checkbtn:) forControlEvents:UIControlEventTouchUpInside];
        
        
        
        UIButton *altbut1=[UIButton buttonWithType:UIButtonTypeCustom];
        [altbut1 setTitle:@"确认" forState:UIControlStateNormal];
        [altbut1 setTitle:@"确认" forState:UIControlStateHighlighted];
        [altbut1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [altbut1 setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [altbut1 setBackgroundColor:[UIColor whiteColor]];
        [altbut1 setTag:1];
        altbut1.frame = CGRectMake(RATIO(270), RATIO(244), RATIO(270), RATIO(100));
        [altbut1 addTarget:self action:@selector(checkbtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:altbut];
        [self addSubview:altbut1];
  
   
    
    
    
}


//-(void)alertview:(id)altview clickbuttonIndex:(NSInteger)index
//{
// 
//    [self alertview:self clickbuttonIndex:index];
//}
//-(void)showmessage
//{
//    NSLog(@"asd");
//}
-(void)handleSingleTap:(UITapGestureRecognizer *)sender
{
    [self hide];
}
-(void)checkbtn:(UIButton *)sender
{
  if([self.deleta respondsToSelector:@selector(alertview:clickbuttonIndex:)])
    [self.deleta alertview:self.view clickbuttonIndex:sender.tag];
    [self hide];
}

-(void)show
{
    if(self==nil)
    {
        self.view = [[UIView alloc] init];
    }
    [self setHidden:NO];
}
-(void)hide
{
    if(self ==nil)
    {
        self.view = [[UIView alloc] init];
    }
    [self setHidden:YES];
    
}
@end
